package com.mf.config;

import io.github.heollhai.common.entity.request.SocketMessageRequest;
import jakarta.validation.Valid;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;

/**
 * @Author: lmf
 * @Create: 2024/11/17 14:57
 * Description:  消息中间件配置
 */
@Configuration

public class RabbitMqConfig {
    // 交换机名称
    public static final String EXCHANGE_NAME = "basic.exchange-topic";
    // 队列名称
    public static final String QUEUE_NAME = "basic.queue-topic";

    /**
     * 完成任务消息key
     */
    public static final String COMPLETE_TASK_KEY = "basic.complete.task";

//       /**
//     * 完成任务消息key
//     */
//    public static final String COMPLETE_TASK_KEY2 = "basic.complete.task2";

    /**
     * 声明交换机
     */
    @Bean("basic.exchange-topic")
    public Exchange declareExchange() {
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    /**
     * 声明队列
     */
    @Bean("basic.queue")
    public Queue declareQueue() {
        return QueueBuilder.durable(QUEUE_NAME).build();
    }


    /**
     * 绑定交换机
     */
    @Bean
    public Binding binding(@Qualifier("basic.queue") Queue queue,@Qualifier("basic.exchange-topic") Exchange exchange){
        return BindingBuilder
                .bind(queue)
                .to(exchange)
                .with(COMPLETE_TASK_KEY)
                .noargs();
    }

//       @Bean
//    public Binding binding2(@Qualifier("basic.queue") Queue queue,@Qualifier("basic.exchange-topic") Exchange exchange){
//        return BindingBuilder
//                .bind(queue)
//                .to(exchange)
//                .with(COMPLETE_TASK_KEY2)
//                .noargs();
//    }

}
